package org.qqcui.designpattern.principles.ocp;

/**
 * 开闭原则示例二，修改成满足开闭原则的方式
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2020-10-14 21:28
 **/
public class Ocp2 {
	public static void main(String[] args) {
		GraphicEditor1 editor = new GraphicEditor1();
		editor.draw(new Rectangle1());
		editor.draw(new Circle1());
		// 新增绘制三角形调用
		editor.draw(new Triangle1());
	}
}

class GraphicEditor1 {
	public void draw(Shape1 s) {
		s.draw();
	}
}

abstract class Shape1 {
	protected abstract void draw();
}

class Rectangle1 extends Shape1 {

	@Override
	public void draw() {
		System.out.println("绘制矩形");
	}
}

class Circle1 extends Shape1 {

	@Override
	public void draw() {
		System.out.println("绘制圆形");
	}
}

/**
 * 新增三角形类
 */
class Triangle1 extends Shape1 {

	@Override
	public void draw() {
		System.out.println("绘制三角形");
	}
}